#include "GW_ADChannel.h"
#include <list>

#define  CNT_AD   8

GW_ADChannel::GW_ADChannel()
{
   this->sum = 0;
}

void GW_ADChannel::setptAD(u32 *pt)
{
   this->ptAD = pt;
}

void GW_ADChannel::setptOUT(u16 *pt)
{
   this->ptOUT = pt;
}

void GW_ADChannel::reflesh()
{
   u16 tmp;
   while(this->listAD.size() >= CNT_AD)
   {
      this->sum -= this->listAD.front();
      this->listAD.pop_front();
   }
   *(this->ptAD) = this->filter.KalmanFilter(*(this->ptAD));
   tmp = *(this->ptAD);
   this->listAD.push_back(tmp);
   this->sum += this->listAD.back();
   //sum = this->filter.KalmanFilter(sum);
}

u32 GW_ADChannel::getChannelAD()
{
   //return (this->sum / CNT_AD);
   //*this->ptOUT = this->filter.KalmanFilter(this->sum);
   *this->ptOUT = BigLittleSwap16(this->sum);
   return *this->ptOUT;
}
